﻿function SaveComment()
{ 
    $.ajax({
        async: true,
        type: "POST",
        url: prependOrgName("/community_topiclist.aspx"),
        data: {
            otype:                  "savecomment",
            title: $("#txtTitle").val(),
            columnid: $("#txtColumnId").val(),
            comments:               $("#txtComments").val(), 
            author:                 $("#txtAuthor").val()
        },
        beforeSend: function() { 
            $("#loading1").css("display", "");
        },
        success: function(data, textStatus) {
            $("#loading1").css("display", "none");
            if(data == "succeeded")
            {
                alert("发布成功！");
                LoadingCommentsList("divcommentslist");
                $("#txtTitle").val("");
                $("#txtComments").val("");
                $("#txtAuthor").val("");
            }
            else {
                if (data == "unlogin")
                    alert("请先登录网站！");
                else
                    alert(data); 
            }
        }
    });
}
function SaveReply()
{
    $.ajax({
        async: true,
        type: "POST",
        url: prependOrgName("/community_topicreplies.aspx"),
        data: {
            otype: "savereply",
            comments: $("#txtComments").val(),
            author: $("#txtAuthor").val(),
            b_id: getUrlParam("b_id")
        },
        beforeSend: function () {
            $("#loading1").css("display", "");
        },
        success: function (data, textStatus) {
            $("#loading1").css("display", "none");
            if (data == "succeeded") {
                alert("回复提交成功！");
                LoadingRepliesList("divcommentslist");
                $("#txtComments").val("");
                $("#txtAuthor").val("");
            }
            else {
                if (data == "unlogin")
                    alert("请先登录网站！");
                else
                    alert(data);
            }
        }
    });
}
function LoadingRepliesList(tagObjectId)
{
    $.ajax({
        async: true,
        type: "POST",
        url: prependOrgName("/community_topicreplies.aspx"),
        data: {
            otype:          "loadingreplies",
            b_id:          getUrlParam("b_id")
        },
        beforeSend: function() {
            $("#"+tagObjectId).html("");
            $("#"+tagObjectId).html($("#loading1").html());
        },
        success: function(data, textStatus) {  
            $("#"+tagObjectId).html("");
            $("#"+tagObjectId).html(data);
        }
    });
    GetRepliesCount();
}
function GetRepliesCount()
{
    $.ajax({
        async: true,
        type: "POST",
        url: prependOrgName("/community_topicreplies.aspx"),
        data: {
            otype:          "getrepliescount",
            b_id:          getUrlParam("b_id")
        }, 
        success: function(data, textStatus) {   
            $("#repliescount").html(data);
        }
    });
}
function ValLoginState() {
    $.ajax({
        async: false,
        type: "POST",
        url: prependOrgName("/community_topiclist.aspx"),
        data: {
            otype: "valloginstate"
        },
        success: function (data, textStatus) {
            if (data == "login")
                return true;
            else
                return false;
        }
    });
}
var _PageIndex;
var _PageUpCount;
var _Direction;
function LoadingCommentsList(tagObjectId)
{ 
    var _querytext = $("#searchReviewKeyWord").val();
    if(_querytext == $("#searchReviewKeyWord").attr("init_value"))
        _querytext = "";
    
    $.ajax({
        async: true,
        type: "POST",
        url: prependOrgName("/community_topiclist.aspx"),
        data: {
            otype: "loadingcommentsitems",
            columnid: $("#txtColumnId").val(), 
            page:           _PageIndex,
            upcount:        _PageUpCount,
            direction:      _Direction,
            querytext:      _querytext
        },
        beforeSend: function() {
            $("#"+tagObjectId).html("");
            $("#"+tagObjectId).html($("#loading1").html());
        },
        success: function(data, textStatus) {  
            $("#"+tagObjectId).html("");
            $("#"+tagObjectId).html(data);
        }
    });
}
function pagination(page, upcount, direction)
{
    _PageIndex=page;
    _PageUpCount=upcount;
    _Direction=direction;
    LoadingCommentsList("divcommentslist");
}
function QueryComments()
{
    _PageIndex=1;
    _PageUpCount=1;
    _Direction="";
    LoadingCommentsList("divcommentslist");
}  
